<?php
namespace Home\Controller;
use Think\Controller;

/**
 * Genre Related Display Controller
 *
 * @package Home\Controller
 * @author lythesia
**/
class GenreController extends Controller {
  /**
   * Display genre index page
   *
   * @param  string genre name
   * @return 
   * @author lythesia
   **/
  public function index($name) {
    $genre_field = 'id,name,description';
    $genre_cond  = array('name' => $name);
    $opt = array(
      'genre_field'   => $genre_field,
      'genre_cond'    => $genre_cond,
      'movie_field'   => 'id,title,releasedate,rating,poster',
      'movie_order'   => 'rating desc',
      'page'          => '1',
      'count'         => '12',
    );
    $opt_side = array(
      'genre_field'   => $genre_field,
      'genre_cond'    => $genre_cond,
      'movie_field'   => 'id,title,releasedate,rating,poster',
      'movie_order'   => 'releasedate desc,rating desc',
      'page'          => '1',
      'count'         => '12',
    );

    $data = A('Common/Genre')->getTopNewMovies($opt);
    if(!$data) goto error;

    $data_side = A('Common/Genre')->getTopNewMovies($opt_side);
    $genres = A('Common/Genre')->getGenres(array(
      'field' => 'id,name', 'limit' => '6'));

    $this->assign('data', $data['movies']);
    $this->assign('data_side', $data_side['movies']);
    $this->assign('genre', $genres);
    $this->assign('current_genre', array(
      'name' => $data['name'],
      'description' => $data['description'],
    ));
    $this->assign('spec_content', 'Movie/movie-genre');

    $this->display('Movie/index-base');
    return;

    error:
    $this->display('Common/404');
  }
}
